<div class="content-wrapper">
	<section class="content-header">
		<h1>
			【{$userInfo.name}】所属的用户组
			<small>已关联的用户组使用<span style='color: red;'>红色</span>标识</small>
		</h1>
		<ol class="breadcrumb">
			<li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
			<li class="active">账号管理</li>
			<li class="active"><a href="/admin/user/userList">用户列表</a></li>
			<li class="active">设置用户权限</li>
		</ol>
	</section>
	<section class="content">
		<div class="box">
			<div class="box-header with-border">
				<input type="hidden" name="user_id" id="user_id" value="{$userInfo.id}" />
				<button type="button" class="btn btn-info" id="save-btn">保存用户权限</button>
			</div>
			<div class="box-body">
				<table class="table table-bordered">
					<tbody>
						<tr>
							<th style="width: 140px">用户组ID</th>
							<th>用户组名</th>
							<th style="width: 215px">操作</th>
						</tr>
						<foreach name="userGroupList" item="userGroup">
                       		<tr>
                       			<td>{$userGroup.id}</td>
                       			<td <if condition="$userGroup.is_checked eq 1">style="color:#FF0000;"</if>>
                       				<label class="position-relative">
                        				<input type="checkbox" name="user_group_id[]" value="{$userGroup.id}" <if condition="$userGroup.is_checked eq 1">checked</if> />
                        				<span style="font-weight:normal;">{$userGroup.name}</span>
                       				</label>
                       			</td>
                       			<td>
                       				<button class="btn btn-info btn-xs" type="button" onclick="window.location.href='/admin/auth/setUserGroupFunction?user_group_id={$userGroup.id}'">设置权限</button>&nbsp;                       				
                       			</td>
                       		</tr>
                       	</foreach>
					</tbody>
				</table>
			</div>			
		</div>
	</section>
</div>

<script type="text/javascript">
$(function(){
	$("#save-btn").click(function(){
		var user_id = $("#user_id").val();
		var userGroupIdList = [];
		$('input[name="user_group_id[]"]:checked').each(function(){
            var user_group_id = $(this).val();
            userGroupIdList.push(user_group_id);
        });
		
		$.post('/admin/user/saveUserFunction', {user_id:user_id, user_group_ids:userGroupIdList.join(',')}, function(data){
			if(data.Code == 999) {
				ArtDialogHlp.showInfo('提示', '操作成功', function(){
					window.location.reload();
				});
			} else {
				ArtDialogHlp.showInfo('提示', data.Msg);
			}
		}, 'json');
	});
});
</script>